//
//  CustomAlertView.m
//  UEAssistant
//
//  Created by mac on 2017/1/24.
//  Copyright © 2017年 youyixinxi. All rights reserved.
//

#import "CustomAlertView.h"

@interface CustomAlertView ()

@property (nonatomic, strong) UIImageView                 *notiView;
@property (nonatomic, strong) UIView                      *backView;
@property (nonatomic, strong) UILabel                     *messageLabel;
@property (nonatomic, strong) UILabel                     *subMessageLabel;
@property (nonatomic, strong) UIButton                    *button;
@property (nonatomic, strong) UIView                      *shadowView;


@end

@implementation CustomAlertView

- (instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
        self.userInteractionEnabled = YES;
    }
    return self;
}

- (void)setUI{

    self.backgroundColor = [UIColor clearColor];
    
    _shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height)];
    _shadowView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.3];
    [self addSubview:_shadowView];
    
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width - 40, 150)];
    _backView.center = self.center;
    _backView.backgroundColor = [UIColor whiteColor];
    _backView.layer.cornerRadius = 3;
    _backView.layer.masksToBounds = YES;
    _backView.userInteractionEnabled = YES;
    [self addSubview:_backView];
    
    _messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, Screen_Width - 60, 30)];
    _messageLabel.center = CGPointMake(self.center.x, self.center.y-10);
    _messageLabel.backgroundColor = [UIColor clearColor];
    _messageLabel.textColor = [UIColor blackColor];
    _messageLabel.textAlignment = NSTextAlignmentCenter;
    _messageLabel.font = [UIFont systemFontOfSize:FLEXIBLE(20)];
    _messageLabel.text = @" 恭喜，抢单成功！";
    [self addSubview:_messageLabel];
    
    _subMessageLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, Screen_Width - 60, 40)];
    _subMessageLabel.center = CGPointMake(self.center.x,self.center.y+40);
    _subMessageLabel.backgroundColor = [UIColor clearColor];
    _subMessageLabel.numberOfLines = 0;
    _subMessageLabel.textColor = [UIColor grayColor];
    _subMessageLabel.textAlignment = NSTextAlignmentCenter;
    _subMessageLabel.font = [UIFont systemFontOfSize:FLEXIBLE(16)];
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:@"请登录网页端，在【我的任务-进行中】页面查看抢到的任务。"];
    [attrString addAttribute:NSForegroundColorAttributeName
                    value:RGB(2, 155, 216, 1)
                    range:NSMakeRange(8, 10)];
    _subMessageLabel.attributedText = attrString;
    [self addSubview:_subMessageLabel];
    
    _button = [UIButton buttonWithType:UIButtonTypeCustom];
    [_button setImage:[UIImage imageNamed:@"succeed"] forState:UIControlStateNormal];
    _button.backgroundColor = RGB(129, 209, 53, 1);
    _button.frame = CGRectMake(0, 0, 60, 60);
    _button.center = CGPointMake(self.center.x, _backView.frame.origin.y);
    _button.layer.cornerRadius = 30;
    _button.layer.masksToBounds = YES;
    [_button addTarget:self action:@selector(customViewCancelResponds) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_button];
    
}

- (void)customViewCancelResponds{

    [self removeFromSuperview];
    [_shadowView removeFromSuperview];
}


@end
